package com.mmy.dao.bidtender;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.bidtender.TBidDetailed;

public interface TBidDetailedRepository extends JpaRepository<TBidDetailed, Integer> {
	/**
	 * 前台个人中心通过投标ID查询投标明细信息
	 * 
	 * 前台修改明细也用到
	 *
	 * @author 创建人 hanxl 整理
	 * @date 创建日期 2020.10.29
	 */
	@Query(value = "select * from tBidDetailed where iTenderID=?1", nativeQuery = true)
	List<TBidDetailed> findByTenderID(int iTenderID);

	/**
	 * 获得最大编号
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.12.10
	 */
	@Query(value = "select Max(iDetailedID) from tBidDetailed where LEFT(iDetailedID,2) = RIGHT(YEAR(NOW()),2)", nativeQuery = true)
	Object getMaxDetailedID();

	/**
	 * 创建修改投标明细
	 * 
	 * @return 返回值说明 最大ID
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.12.10
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tBidDetailed(iDetailedID, iTenderID, cDetailedName, cContent, cHotelPath1, cHotelPath2, cHotelPath3, cHotelPath4, fBudget, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (?1, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(int detailedID);

	/**
	 * 通过itenderID删除明细 修改明细功能用到
	 * 
	 * @author 创建人 hanxl
	 * @date 创建日期 2020.12.14
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tBidDetailed where iTenderID =?1", nativeQuery = true)
	void deleteByTenderID(int iTenderID);

	@Transactional
	@Modifying
	@Query(value = "delete from tBidDetailed where iDetailedID in(:iTenderIDs)", nativeQuery = true)
	void deleteChecked(@Param("iTenderIDs") List<Integer> iTenderIDs);

}
